package cloud.daodao.storm.common.user.api;

import cloud.daodao.storm.common.constant.AppConstant;
import cloud.daodao.storm.common.model.No;
import cloud.daodao.storm.common.model.Ok;
import cloud.daodao.storm.common.model.Request;
import cloud.daodao.storm.common.model.Response;
import cloud.daodao.storm.common.user.constant.UserConstant;
import cloud.daodao.storm.common.user.model.oauth2.IdLogin;
import cloud.daodao.storm.common.user.model.oauth2.Login;
import cloud.daodao.storm.common.user.model.oauth2.OAuth2;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.service.annotation.HttpExchange;
import org.springframework.web.service.annotation.PostExchange;

/**
 * @author DaoDao
 */
@Tag(name = "OAuth2Api", description = "OAuth2")
@HttpExchange(url = AppConstant.API)
public interface OAuth2Api {

    @Operation(summary = "登录", description = "@DaoDao 传入 username & password 信息，获取 token")
    @PostExchange(url = UserConstant.LOGIN)
    Response<OAuth2> login(@RequestBody @Valid Request<Login> request);

    @Operation(summary = "id 登录", description = "@DaoDao 传入 id 信息，获取 token，此接口仅允许受信任的后端内部服务调用")
    @PostExchange(url = UserConstant.ID_LOGIN)
    Response<OAuth2> idLogin(@RequestBody @Valid Request<IdLogin> request);

    @Operation(summary = "退出", description = "@DaoDao header 中传入 token 信息，退出登录")
    @PostExchange(url = UserConstant.LOGOUT)
    Response<Ok> logout(@RequestHeader(HttpHeaders.AUTHORIZATION) String authorization, @RequestBody @Valid Request<No> request);

}
